import Vue from 'vue'
import App from './App.vue'
// import router from './router'
import Router from 'vue-router'
import store from './store'
import Home from "./components/Home"
import Menu from "./components/Menu"
import Admin from "./components/Admin"
import about from "./components/about/about"
import login from "./components/login"
import Register from "./components/Register"

//二级路由
import Contact from "./components/about/Contact"
import History from "./components/about/History"
import Delivery from "./components/about/Delivery"
import Ordering from "./components/about/Ordering"

//三级路由
import Phone from "./components/about/content/Phone"
import PersonName from "./components/about/content/PersonName"
Vue.config.productionTip = false
Vue.use(Router)
const routes = [
  {path:"/",name:"HomeLink",component:Home},
  {path:"/Menu",name:"MenuLink",component:Menu},
  {path:"/Admin",name:"AdminLink",component:Admin,beforeEnter:(to, from, next) => {
    // if(to.path == '/login' || to.path == '/Register'){
    //   next();
    // }else{
    //   alert("对不起，请先登录");
    //   next('/login');
    // }
    alert('不是登录状态，无法访问此页面');
    next('/login');
  }
  },
  {path:"/about",name:"aboutLink",redirect:"/about/contact",component:about,children:[
    //二级路由
    {path:"/about/contact",name:"contactLink",redirect:"/personname",component:Contact,children:[
      //三级路由
      {path:"/phone",name:"phoneNumber",component:Phone},
      {path:"/personname",name:"personName",component:PersonName},
    ]},
    {path:"/history",name:"historyLink",component:History},
    {path:"/delivery",name:"deliveryLink",component:Delivery},
    {path:"/ordering",name:"orderingLink",component:Ordering},
  ]},
  {path:"/login",name:"loginLink",component:login},
  {path:"/Register",name:"RegisterLink",component:Register},
  {path:"*",redirect:"/"},
  
]
const router = new Router({
  routes,
  mode:"history" 
})
//全局守卫 
// router.beforeEach((to,from,next)=>{
//   // alert("请先登录")
//   // console.log(to);
// if(to.path == '/login' || to.path == '/Register'){
//   next();
// }else{
//   alert("对不起，请先登录");
//   next('/login');
// }
  
// })
new Vue({
  el:"#app",
  render: h => h(App),
  router,
  store,
  
})
